package com.wx.payment.controller;

import com.wx.commons.result.R;
import com.wx.payment.dao.entity.Payment;
import com.wx.payment.service.PaymentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @author: 王霄
 * @date: 2021/12/24 20:48
 */
@RestController
@RequestMapping("/payment")
public class PaymentController {

    @Resource
    private PaymentService paymentService;

    @PostMapping(value = "/create")
    public R<?> create(@RequestBody Payment payment) {
        paymentService.save(payment);
        return R.ok();
    }

    @GetMapping(value = "/queryById/{id}")
    public R<Payment> queryById(@PathVariable("id") long id) {
        return R.ok(paymentService.getById(id));
    }

    @GetMapping(value = "/queryByIdTimeout/{id}")
    public R<Payment> queryByIdTimeout(@PathVariable("id") long id) {
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return R.ok(paymentService.getById(id));
    }
}
